home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / wdj0697.zip / WIESMAN.ZIP / CTRLDLG.CPP < prev    next >
C/C++ Source or Header  |  1997-01-20  |  5KB  |  202 lines

  1. // CtrlDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "CCApp.h"
  6. #include "CtrlDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16.  
  17. class CAboutDlg : public CDialog
  18. {
  19. public:
  20.     CAboutDlg();
  21.  
  22. // Dialog Data
  23.     //{{AFX_DATA(CAboutDlg)
  24.     enum { IDD = IDD_ABOUTBOX };
  25.     //}}AFX_DATA
  26.  
  27.     // ClassWizard generated virtual function overrides
  28.     //{{AFX_VIRTUAL(CAboutDlg)
  29.     protected:
  30.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  31.     //}}AFX_VIRTUAL
  32.  
  33. // Implementation
  34. protected:
  35.     //{{AFX_MSG(CAboutDlg)
  36.     //}}AFX_MSG
  37.     DECLARE_MESSAGE_MAP()
  38. };
  39.  
  40. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  41. {
  42.     //{{AFX_DATA_INIT(CAboutDlg)
  43.     //}}AFX_DATA_INIT
  44. }
  45.  
  46. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  47. {
  48.     CDialog::DoDataExchange(pDX);
  49.     //{{AFX_DATA_MAP(CAboutDlg)
  50.     //}}AFX_DATA_MAP
  51. }
  52.  
  53. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  54.     //{{AFX_MSG_MAP(CAboutDlg)
  55.         // No message handlers
  56.     //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CCustCtrlDlg dialog
  61.  
  62. CCustCtrlDlg::CCustCtrlDlg(CWnd* pParent /*=NULL*/)
  63.     : CDialog(CCustCtrlDlg::IDD, pParent)
  64. {
  65.     //{{AFX_DATA_INIT(CCustCtrlDlg)
  66.         // NOTE: the ClassWizard will add member initialization here
  67.     //}}AFX_DATA_INIT
  68.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  69.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  70. }
  71.  
  72. void CCustCtrlDlg::DoDataExchange(CDataExchange* pDX)
  73. {
  74.     CDialog::DoDataExchange(pDX);
  75.     //{{AFX_DATA_MAP(CCustCtrlDlg)
  76.         // NOTE: the ClassWizard will add DDX and DDV calls here
  77.     //}}AFX_DATA_MAP
  78.     DDX_Control(pDX, IDC_CLOCK, m_clock);
  79.     DDX_Control(pDX, IDC_DIAL, m_dial);
  80.     DDX_Control(pDX, IDC_DIAL2, m_dial2);
  81.     DDX_Control(pDX, IDC_DIAL3, m_dial3);
  82. }
  83.  
  84. BEGIN_MESSAGE_MAP(CCustCtrlDlg, CDialog)
  85.     //{{AFX_MSG_MAP(CCustCtrlDlg)
  86.     ON_WM_SYSCOMMAND()
  87.     ON_WM_PAINT()
  88.     ON_WM_QUERYDRAGICON()
  89.     ON_WM_TIMER()
  90.     ON_WM_DESTROY()
  91.     //}}AFX_MSG_MAP
  92.     ON_CONTROL(DN_UP, IDC_DIAL, OnDial)
  93.     ON_CONTROL(DN_DOWN, IDC_DIAL, OnDial)
  94.     ON_CONTROL(DN_CLICK, IDC_DIAL, OnDial)
  95. END_MESSAGE_MAP()
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CCustCtrlDlg message handlers
  99.  
  100. BOOL CCustCtrlDlg::OnInitDialog()
  101. {
  102.     CDialog::OnInitDialog();
  103.  
  104.     // Add "About..." menu item to system menu.
  105.  
  106.     // IDM_ABOUTBOX must be in the system command range.
  107.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  108.     ASSERT(IDM_ABOUTBOX < 0xF000);
  109.  
  110.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  111.     CString strAboutMenu;
  112.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  113.     if (!strAboutMenu.IsEmpty())
  114.     {
  115.         pSysMenu->AppendMenu(MF_SEPARATOR);
  116.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  117.     }
  118.  
  119.     // Set the icon for this dialog.  The framework does this automatically
  120.     //  when the application's main window is not a dialog
  121.     SetIcon(m_hIcon, TRUE);            // Set big icon
  122.     SetIcon(m_hIcon, FALSE);        // Set small icon
  123.     
  124.     // set timer for updating the clock control
  125.     SetTimer(0, 1000, NULL);
  126.     m_clock.SetToCurrentTime();
  127.     return TRUE;  // return TRUE  unless you set the focus to a control
  128. }
  129.  
  130. void CCustCtrlDlg::OnSysCommand(UINT nID, LPARAM lParam)
  131. {
  132.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  133.     {
  134.         CAboutDlg dlgAbout;
  135.         dlgAbout.DoModal();
  136.     }
  137.     else
  138.     {
  139.         CDialog::OnSysCommand(nID, lParam);
  140.     }
  141. }
  142.  
  143. // If you add a minimize button to your dialog, you will need the code below
  144. //  to draw the icon.  For MFC applications using the document/view model,
  145. //  this is automatically done for you by the framework.
  146.  
  147. void CCustCtrlDlg::OnPaint() 
  148. {
  149.     if (IsIconic())
  150.     {
  151.         CPaintDC dc(this); // device context for painting
  152.  
  153.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  154.  
  155.         // Center icon in client rectangle
  156.         int cxIcon = GetSystemMetrics(SM_CXICON);
  157.         int cyIcon = GetSystemMetrics(SM_CYICON);
  158.         CRect rect;
  159.         GetClientRect(&rect);
  160.         int x = (rect.Width() - cxIcon + 1) / 2;
  161.         int y = (rect.Height() - cyIcon + 1) / 2;
  162.  
  163.         // Draw the icon
  164.         dc.DrawIcon(x, y, m_hIcon);
  165.     }
  166.     else
  167.     {
  168.         CDialog::OnPaint();
  169.     }
  170. }
  171.  
  172. // The system calls this to obtain the cursor to display while the user drags
  173. //  the minimized window.
  174. HCURSOR CCustCtrlDlg::OnQueryDragIcon()
  175. {
  176.     return (HCURSOR) m_hIcon;
  177. }
  178.  
  179. void CCustCtrlDlg::OnTimer(UINT nIDEvent) 
  180. {
  181.     m_clock.SetToCurrentTime();
  182.     m_clock.Invalidate();
  183.     CDialog::OnTimer(nIDEvent);
  184. }
  185.  
  186. void CCustCtrlDlg::OnDestroy() 
  187. {
  188.     CDialog::OnDestroy();
  189.     
  190.     KillTimer(0);
  191. }
  192.  
  193.  
  194. void CCustCtrlDlg::OnDial() 
  195. {
  196.     CString str;
  197.  
  198.     str.Format(IDS_VALFORMAT, m_dial.m_nValue);
  199.     GetDlgItem(IDC_ST_VALUE)->SetWindowText(str);
  200.     return;
  201. }
  202.